package com.qingcheng.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qingcheng.entity.Result;
import com.qingcheng.service.system.AdminService;
import com.qingcheng.service.system.MenuService;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/main")
public class MainController {

    @Reference(timeout = 60000)
    private MenuService menuService;

    @Reference
    private AdminService adminService;

    @GetMapping("/findMenu")
    public List<Map> findMenu(){
        //获取认证的用户名
        String loginName = SecurityContextHolder.getContext().getAuthentication().getName();
        return menuService.findMenu(loginName);
    }


    /**
     * 定义查询所有菜单的方法
     * @return
     */
    @GetMapping("/findAllMenu")
    public List<Map> findAllMenu(){
        return menuService.findAllMenu();
    }

    @GetMapping("/findUsername")
    public String findUsername(){
        String username = SecurityContextHolder.getContext().getAuthentication().getName();
        return username;
    }

    @PostMapping("/editPassword")
    public Result editPassword(@RequestBody Map<String,String> searchMap){
        adminService.editPassword(searchMap);
        return new Result();
    }

}
